package com.throttle.raildroid;
import java.util.ArrayList;
import java.util.EventListener;

import javax.swing.event.EventListenerList;

public class TestEventHandler{
	protected ArrayList<RailEventListenerInf> listenerList = new ArrayList<RailEventListenerInf>();
	
	public void addRailEventListener(RailEventListenerInf listener) {
        listenerList.add(listener);
    }
	
	public void removeRailEventListener(RailEventListenerInf listener) {
        listenerList.remove(listener);
    }
	
	void fireMyEvent(RailEvent evt) {
        Object[] listeners = listenerList.toArray();
        // Each listener occupies two elements - the first is the listener class
        // and the second is the listener instance
        for (int i=0; i<listeners.length; i+=1) {
            ((RailEventListenerInf)listeners[i]).RailEventOccurred(evt);
        }
    }
}
